<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <title>编辑任务</title>
  <div th:replace="common/link::header"></div>
</head>
<body>
<div class="layui-fluid">
  <div class="layui-row">
    <div class="layui-form" lay-filter="sys-task-form" id="sys-task-form">
      <input type="hidden" name="id" id="id">
      <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline">
          <input type="text" name="name" lay-verify="required" placeholder="请输入名称" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">表达式</label>
        <div class="layui-input-inline">
          <input id="cron" type="text" name="cron" lay-verify="required" placeholder="请输入表达式" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">类名称</label>
        <div class="layui-input-inline">
          <input type="text" name="className" lay-verify="required" placeholder="请输入类名称" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">方法名</label>
        <div class="layui-input-inline">
          <input type="text" name="methodName" lay-verify="required" placeholder="请输入方法名" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block" id="enabled"></div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
          <textarea class="layui-textarea" name="remark" placeholder="请输入备注"></textarea>
        </div>
      </div>
      <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="save-submit" id="save-submit" value="确认">
      </div>
    </div>
  </div>
</div>
<div th:replace="common/script::footer"></div>
<script th:inline="javascript">
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
    }).use(['index', 'form','crud'], function(){
        let $ = layui.$,
                crud = layui.crud,
                form = layui.form,
                sysTask = [[${sysTask}]];
        form.val('sys-task-form', sysTask);
        form.on('submit(save-submit)', function(data){
            $.ajax({
                type: 'POST',
                url:  ctx + '/sysTask/edit',
                data: JSON.stringify(data.field),
                contentType:'application/json;charset=UTF-8',
                dataType: 'json',
                success: function(result) {
                    layer.msg(result.message);
                    if (result.code === 200) {
                        let index = parent.layer.getFrameIndex(window.name);
                        // 关闭
                        parent.layer.close(index);
                        // 刷新
                        parent.location.reload();
                    }
                }
            });
        });
        crud.setRadio("enabled","enabled",sysTask.enabled);

      $('#cron').on('click', function(){
        layer.open({
          type: 2,
          title: "Cron表达式生成器",
          content: ctx + '/sysTask/cronPage'
          ,maxmin: true
          ,area: ['500px', '450px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            let iframeWin = window[layero.find('iframe')[0]['name']];
            let cron = iframeWin.document.getElementById("cron").value;
            $("#cron").val(cron);
            layer.close(index);
          }
        });
      });
    })
</script>
</body>
</html>